package cn.gzsxt.music.mapper;

import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;

import cn.gzsxt.music.query.UserCollectQueryObject;

@Mapper
public class UserCollectProvider {
	public String selectUsListByQo(UserCollectQueryObject qo) {
		StringBuilder sql = new StringBuilder();
		sql.append("SELECT l.*,u.user_name,s.songList_name FROM mc_uslist l,mc_user u,mc_songlist s WHERE l.user_id = u.user_id AND l.songList_id = s.songList_id");
		if (StringUtils.isNotBlank(qo.getSname())) {
			sql.append(" and user_name like \"%\"#{sname}\"%\"");
		}
		if (StringUtils.isNotBlank(qo.getSdate())) {
			sql.append(" and usList_date = #{sdate}");
		}
		sql.append(" limit #{beginIndex},#{rows}");
		return sql.toString();
	}
	public String getUsListTotalByQo(UserCollectQueryObject qo) {
		StringBuilder sql = new StringBuilder();
		sql.append("select count(*) from mc_uslist l,mc_user u,mc_songlist s WHERE l.user_id = u.user_id AND l.songList_id = s.songList_id");
		if (StringUtils.isNotBlank(qo.getSname())) {
			sql.append(" and user_name like \"%\"#{sname}\"%\"");
		}
		if (StringUtils.isNotBlank(qo.getSdate())) {
			sql.append(" and usList_date = #{sdate}");
		}
		return sql.toString();
	}
	
	public String selectUcListByQo(UserCollectQueryObject qo) {
		StringBuilder sql = new StringBuilder();
		sql.append("select l.*,u.user_name,c.cd_name from mc_uclist l,mc_user u,mc_cd c where l.user_id = u.user_id and l.cd_id = c.cd_id");
		if (StringUtils.isNoneBlank(qo.getSname())) {
			sql.append(" and user_name like \"%\"#{sname}\"%\"");
		}
		if (StringUtils.isNotBlank(qo.getSdate())) {
			sql.append(" and ucList_date = #{sdate}");
		}
		sql.append(" limit #{beginIndex},#{rows}");
		return sql.toString();
	}
	public String getUcListTotalByQo(UserCollectQueryObject qo) {
		StringBuilder sql = new StringBuilder();
		sql.append("select count(*) from mc_uclist l,mc_user u,mc_cd c where l.user_id = u.user_id and l.cd_id = c.cd_id");
		if (StringUtils.isNotBlank(qo.getSname())) {
			sql.append(" and user_name like \"%\"#{sname}\"%\"");
		}
		if (StringUtils.isNotBlank(qo.getSdate())) {
			sql.append(" and ucList_date = #{sdate}");
		}
		return sql.toString();
	}
	
	public String selectUsrListByQo(UserCollectQueryObject qo) {
		StringBuilder sql = new StringBuilder();
		sql.append("SELECT l.*,u.user_name,s.singer_name FROM mc_user u,mc_usrlist l,mc_singer s WHERE l.user_id = u.user_id AND l.singer_id = s.singer_id");
		if (StringUtils.isNoneBlank(qo.getSname())) {
			sql.append(" and user_name like \"%\"#{sname}\"%\"");
		}
		if (StringUtils.isNotBlank(qo.getSdate())) {
			sql.append(" and usrList_date = #{sdate}");
		}
		sql.append(" limit #{beginIndex},#{rows}");
		return sql.toString();
	}
	public String getUsrListTotalByQo(UserCollectQueryObject qo) {
		StringBuilder sql = new StringBuilder();
		sql.append("select count(*) from mc_user u,mc_usrlist l,mc_singer s WHERE l.user_id = u.user_id AND l.singer_id = s.singer_id");
		if (StringUtils.isNotBlank(qo.getSname())) {
			sql.append(" and user_name like \"%\"#{sname}\"%\"");
		}
		if (StringUtils.isNotBlank(qo.getSdate())) {
			sql.append(" and usrList_date = #{sdate}");
		}
		return sql.toString();
	}
}
